export async function copyPageUrl() {
  try {
    await navigator.clipboard.writeText(location.href)
    console.log('copyPageUrl--------Page URL copied to clipboard--------已复制到剪切板')
  } catch (err) {
    console.error('Failed to copy: ', err)
  }
}
export async function getClipboardContents() {
  try {
    const text = await navigator.clipboard.readText()
    console.log('getClipboardContents-----------Pasted content:（剪切板内容是：） ', text)
  } catch (err) {
    console.error('Failed to read clipboard contents: ', err)
  }
}

// document.addEventListener('paste', async (e) => {
//   let text
//   if (navigator.clipboard) {
//     text = await navigator.clipboard.readText()
//   } else {
//     text = e.clipboardData.getData('text/plain')
//   }
//   console.log('监听到剪切事件------Got pasted text: ', text)
// })

navigator.permissions
  .query({
    name: 'clipboard-read',
  })
  .then((permissionStatus) => {
    // permissionStatus.state 的值是 'granted'、'denied'、'prompt':
    console.log('permissionStatus.state:', permissionStatus.state)

    // 监听权限状态改变事件
    permissionStatus.onchange = () => {
      console.log('permissionStatus.state:', permissionStatus.state)
    }
  })
